package com.zy.openchat.core.model.circle;

import android.os.Parcel;
import android.os.Parcelable;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.zy.openchat.core.model.user.UserInfo;

import java.util.List;

public class BlogReplyInfo implements Parcelable , MultiItemEntity {
    public InputBlogIdType blog_id;
    public long id;
    public long user_id;
    public String text;
    public long date;
    public boolean liked;
    public int like_count;
    public long reply_id;

//    public BlogLikeInfo likes;
//    public BlogReplysInfo replys;
    public boolean isExpand = false;
    public int reply_count;
    public long reply_user_id;

    public boolean isRequestReplys = false;
    public List<BlogReplyInfo> replys;

    @Override
    public int getItemType() {
        return 1;
    }


    public boolean isMessageEqual(BlogReplyInfo blogInfo){
        if(blogInfo==null){
            return false;
        }
        return id == blogInfo.id;
    }

    public boolean isAvaterDownloaded = false;

    public boolean isAvaterDownloadEqual(BlogReplyInfo fullInfo){
        if(fullInfo==null){
            return false;
        }
        UserInfo oldUserInfo = UserInfo.getUserInfo(user_id);
        UserInfo newUserInfo = UserInfo.getUserInfo(fullInfo.user_id);
        if(oldUserInfo==null&&newUserInfo==null){
            return true;
        }
        if(oldUserInfo==null||newUserInfo==null){
            return false;
        }
        boolean newIsAvaterDownloaded = false;
        if(newUserInfo.profile_photo!=null&&newUserInfo.profile_photo.isSmallPhotoDownloaded()){
            newIsAvaterDownloaded = true;
        }
        return newIsAvaterDownloaded == isAvaterDownloaded;
    }

    public int likeNumber(){
        return like_count;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.blog_id, flags);
        dest.writeLong(this.id);
        dest.writeLong(this.user_id);
        dest.writeString(this.text);
        dest.writeLong(this.date);
        dest.writeByte(this.liked ? (byte) 1 : (byte) 0);
        dest.writeInt(this.like_count);
        dest.writeLong(this.reply_id);
        dest.writeInt(this.reply_count);
        dest.writeLong(this.reply_user_id);
    }

    public void readFromParcel(Parcel source) {
        this.blog_id = source.readParcelable(InputBlogIdType.class.getClassLoader());
        this.id = source.readLong();
        this.user_id = source.readLong();
        this.text = source.readString();
        this.date = source.readLong();
        this.liked = source.readByte() != 0;
        this.like_count = source.readInt();
        this.reply_id = source.readLong();
        this.reply_count = source.readInt();
        this.reply_user_id = source.readLong();
    }

    public BlogReplyInfo() {
    }

    protected BlogReplyInfo(Parcel in) {
        this.blog_id = in.readParcelable(InputBlogIdType.class.getClassLoader());
        this.id = in.readLong();
        this.user_id = in.readLong();
        this.text = in.readString();
        this.date = in.readLong();
        this.liked = in.readByte() != 0;
        this.like_count = in.readInt();
        this.reply_id = in.readLong();
        this.reply_count = in.readInt();
        this.reply_user_id = in.readLong();
    }

    public static final Creator<BlogReplyInfo> CREATOR = new Creator<BlogReplyInfo>() {
        @Override
        public BlogReplyInfo createFromParcel(Parcel source) {
            return new BlogReplyInfo(source);
        }

        @Override
        public BlogReplyInfo[] newArray(int size) {
            return new BlogReplyInfo[size];
        }
    };
}
